<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/static/admin/jsp/include.jsp"%>
    <style type="text/css">
        .textbox.textbox-focused .textbox-addon,
        .textbox.textbox-focused .textbox-text{
            background: #eee!important;
        }
    </style>
    <script type="text/javascript">
        var id = "${id}";
        var type = "${type}";
        submitForm = function($dialog, $grid, $pjq) {
            if ($('form').form('validate')) {
                var obj=sy.serializeObject($('form'));
                var url=sy.contextPath + '/ageParam/save';
                var data = [];
                for (var i = 0; i < resultJson; i++){
                    obj.chemicalType = id;
                    var sex = $('#sex'+i).combobox('getValue');
                    var param = $('#param'+i).val();
                    var age = $('#age'+i).val();
                    var num = $('#num'+i).val();
                    var json = {sex:sex,param:param,age:age,num:num};

                    data.push(json);
                }
                obj.data = sy.jsonToString(data);
                obj.chemialType = id;
                parent.$.messager.confirm('询问', '确定保存？', function(r) {
                    if (r) {
                        $.post(url, obj, function(result) {
                            if (result.code == 0) {
                                parent.$.messager.i('保存成功');
                                $grid.datagrid('reload');
                                $dialog.dialog('destroy');
                            } else {
                                $pjq.messager.e('保存失败,'+result.msg);
                            }
                        }, 'json');
                    }
                });
            }
        };

        $(function() {
            if(id != ''){
                $.post(sy.contextPath + '/ageParam/getParamList', {
                    chemicalType : id,
                }, function(result) {
                    if (id != '') {
//                        parent.$.messager.progress({
//                            text : '数据加载中....'
//                        });
                        $.post(sy.contextPath + '/ageParam/getParamList', {
                            chemicalType : id
                        }, function(result) {
                            if(result.length != 0){
                                var data = sy.stringToJSON(result[0].data);
                                console.log(data);
                                for (var i = 0; i< data.length; i++){
                                    add();
                                    $('#sex'+i).combobox('setValue',data[i].sex);
                                    $('#age'+i).textbox('setValue',data[i].age);
                                    $('#param'+i).textbox('setValue',data[i].param);
                                    $('#num'+i).textbox('setValue',data[i].num);
                                }
                            }
                            parent.$.messager.progress('close');
                        }, 'json');

                    }
                })
            }
        });

        var resultJson = 0;
        function add(){
            var htmls = '';

            htmls +=
                '<tr id="data'+resultJson+'" >' +
                '<th style="width:40px;">'+('X坐标')+'</th>'+
                '<td>'+
                '<input style="width: 70px;" id="age'+resultJson+'" name="age'+resultJson+'" class="easyui-textbox" data-options="validType:['+'length[0,300]'+'],multiline : true" missingMessage="请输入'+('X坐标')+'"/>'+
                '</td>'+
                '<th style="width:30px;">'+('性别')+'</th>'+
                '<td>'+
//                '<input style="width: 80px;" id="sex'+resultJson+'" name="sex'+resultJson+'" class="easyui-textbox" data-options="validType:['+'length[0,300]'+'],multiline : true" missingMessage="请输入'+('参数')+'"/>'+
                '<select style="width:80%;" id="sex'+resultJson+'" class="easyui-combobox" name="sex'+resultJson+'" data-options="required:true,editable:false">' +
                    '<option value="1">男</option>'+
                    '<option value="2">女</option>'+
                '</select>'+
                '</td>'+
                '<th style="width:40px;">'+('Y坐标')+'</th>'+
                '<td>'+
                '<input style="width: 70px;" id="param'+resultJson+'" name="param'+resultJson+'" class="easyui-textbox" data-options="validType:['+'length[0,300]'+'],multiline : true" missingMessage="请输入'+('Y坐标')+'"/>'+
                '</td>'+
                '<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:\'fa-trash\',plain:true" onclick="delTuwen('+resultJson+')">删除</a></td>'+
                '<th style="width:40px;">'+('数量')+'</th>'+
                '<td>'+
                '<input style="width: 70px;" id="num'+resultJson+'" name="num'+resultJson+'" class="easyui-textbox" data-options="validType:['+'length[0,300]'+'],multiline : true" missingMessage="请输入'+('数量')+'"/>'+
                '</td>'+
                '<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:\'fa-trash\',plain:true" onclick="delTuwen('+resultJson+')">删除</a></td>'+
                '</tr>';


            $("#resultJson").append(htmls);
            $.parser.parse('#data'+resultJson);
//            $.parser.parse('#sexs'+resultJson);
//            $.parser.parse('#params'+resultJson);
            resultJson++;
        }

        function delTuwen(index){
            $('#data'+index).remove();
        }

    </script>
</head>
<body>
<form id="form" method="post">
    <input name="id" type="hidden" />
    <div style="padding:15px;font-size: 12px">
        <table style="table-layout:fixed;" border="0" cellspacing="0" class="formtable">
            <tr >
                <th style="width: 100px">参数对照</th>
                <td colspan="3">
                    <div id="addBtn"><a href="javascript:void(0);" class="easyui-linkbutton" onclick="add()">添加</a></div>
                    <table style="table-layout:fixed;" border="0" cellspacing="0" class="formtable" id='resultJson'>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</form>
</body>
</html>